package cn.rhl.projectinit.exception;

import cn.rhl.projectinit.common.ResponseCode;

/**
 * @author rhl
 * @date 2024/12/22
 */
public class ThrowErrorUtils {

    /**
     * 条件成立，则抛出指定异常
     *
     * @param condition        条件
     * @param runtimeException 指定异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立，则抛出业务异常与响应码信息
     * @param condition  条件
     * @param responseCode 响应码
     */
    public static  void throwIf(boolean condition, ResponseCode responseCode){
        throwIf(condition,new BusinessException(responseCode));
    }

    /**
     * 条件成立，则抛出业务异常与指定信息
     * @param condition  条件
     * @param responseCode 响应码
     * @param msg 指定信息
     */
    public static  void throwIf(boolean condition,ResponseCode responseCode,String msg){
        throwIf(condition,new BusinessException(responseCode,msg));
    }
}
